<template>
	<view>
		<view class="header status_bar" :class="scrrol == true ? 'scrrolHeader' : ''">
			<!-- <view class="back iconfont icon-xiangzuo1" @tap="backPage"></view> -->
			<view class="text" :class="scrrol == true ? 'scrrolHeader' : ''">车界网</view>
		</view>
		<view class="search_maxbox" :class="scrrol == true ? 'scrrolHeader02' : ''">
			<view class="search_box">
				<view class="search">
					<view class="icon iconfont icon-sousuo"></view>
					<input type="text" v-model="keyword" value="" placeholder="搜索群名称" />
					<view class="menu" @click="search">搜索</view>
				</view>
			</view>
		</view>
		<view class="clear_box"></view>
		<view class="clear_box02"></view>
		<view class="rule_box">
			<view class="icon iconfont icon-tongzhi2"></view>
			<view class="value">开通一年会员可免费加入会员批车群</view>
			<view class="add" :data-url="'/pages/personalcenter/member/member'" @click="gotopage">去加入</view>
			<view class="arrow iconfont icon-xiangyou1"></view>
		</view>

		<block v-for="(item,index) in info">
			<view class="group_list">
				<view class="group_img">
					<image :src="item.thumb" mode="widthFix"></image>
				</view>
				<view class="group_text">
					<view class="title">{{item.name}}</view>
					<view class="text">{{item.num}}人 | {{item.description}}</view>
				</view>
				<view class="group_menu" @tap="join(item.image)">加群</view>
			</view>
		</block>
		<view class="pupu_box" @tap="closePupu" v-if="pupu">
			<view class="pupu_show" @tap.stop="">
				<view class="pupu_title">扫码加群</view>
				<view class="close iconfont icon-guanbi1" @tap="closePupu"></view>
				<view class="pupu_value">
					<view class="ewm">
						<image :src="image" show-menu-by-longpress="true" mode="widthFix"></image>
					</view>
					<view class="pupu_menu" @tap="closePupu">长按二维码添加客服</view>
					
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				scrrol: false,
				info: '',
				is_vip: 0,
				keyword: '',
				pupu:false,
				image:'',
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			setRule(e) {
				let that = this;
				let index = e.currentTarget.dataset.index;
				that.flowList[index].tick = !that.flowList[index].tick
			},
			loadData() {
				let that = this;
				that.Net._get('other/group', {keyword:that.keyword,page:that.page}, res => {
					if (res.code == 1) {
						that.info = res.data.data;
						that.is_vip = res.data.is_vip;
					}
				});
			},
			search(){
				if (this.keyword == ''){
					that.Msg.Fail('请输入内容');
					return '';
				}
				this.page = 1;
				this.loadData();
			},
			join(url){
				let token = uni.getStorageSync('_TOKEN_')
				if (!token) {
					uni.showModal({
					    title: '温馨提示',
					    content: '您还未登录，请先登录',
						cancelText:'暂不登录',
						confirmText:'去登录',
					    success: function (res) {
					        if (res.confirm) {
								uni.navigateTo({
									url: '/pages/public/login'
								});
					        } else if (res.cancel) {
					            console.log('用户点击取消');
					            // 用户点击了取消按钮的相关逻辑可以放在这里
					        }
					    }
					})
					return '';
				}
				if (this.is_vip == 0){
					uni.showModal({
					    title: '提示',
					    content: '您当前不是会员，无法加入群聊',
						confirmText:'去开通',
					    success: function (res) {
					        if (res.confirm) {
								uni.navigateTo({
									url: '/pages/personalcenter/member/member'
								});
								return '';
					        } else if (res.cancel) {
								
					        }
					    }
					})
					return '';
				}
				this.image = url;
				this.pupu = !this.pupu;
			},
			closePupu(){
				let that = this;
				that.pupu = !that.pupu;
			},
			backPage() {
				uni.navigateBack({});
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},

		},
		onPageScroll: function(Object) {
			//console.log(Object.scrollTop); //实时获取到滚动的值
			if (Object.scrollTop > 28) {
				this.scrrol = true;
				/* #ifdef APP-PLUS */
				/* #endif */
			} else if (Object.scrollTop < 28) {
				this.scrrol = false;
				/* #ifdef APP-PLUS */
				/* #endif */
			}
		},
		onReachBottom() {
			var that = this;
			that.page++;
			that.Net._get('other/group', {per_page:'10',page:that.page,keyword:that.keyword}, res => {
			  if (res.code == 1) {
			    //console.log(res)
			    if (res.data.data == '') {
			      uni.showToast({
			        title: '没有更多了',
			        duration: 2000,
			        icon: 'none'
			      });
			    } else {
			      that.info = that.info.concat(res.data.data); //将数据拼接在一起
			    }
			  } else if (res.code == 0) {
			    that.Msg.Success(res.msg, res => {});
			  }
			});
		},
	}
</script>

<style>
	.header {
		/* background-color: transparent !important; */
	}

	.header .text {
		/* background-color: transparent !important; */
		color: #fff !important;
	}
	
	.scrrolHeader02{
		background-color: #fff !important;
	}

	.clear_box02 {
		width: 100%;
		height: calc(12vw + var(--status-bar-height));
	}

	.search_maxbox {
		width: 100%;
		padding: 3vw 4%;
		position: fixed;
		left: 0;
		top: calc(13.4vw + var(--status-bar-height));
		z-index: 98;
	}

	.search_box {
		width: 100%;
		border-radius: 2vw;
		border: 1px solid #FC5D20;
		display: flex;
		align-items: center;
		height: 12vw;
		padding-left: 2vw;
	}

	.search_box .city_box {
		display: flex;
		align-items: center;
		padding: 0 2vw;
		border-right: 1px solid #E8E8F0;
		margin-right: 2vw;
	}

	.search_box .city_box .city {
		font-size: 3.8vw;
		color: #979AA9;
		margin-right: 1vw;
	}

	.search_box .city_box .arrow {
		font-size: 3vw;
		color: #979AA9;
	}

	.search_box .search {
		flex: 1;
		display: flex;
		align-items: center;
	}

	.search_box .search .icon {
		font-size: 4vw;
		color: #979AA9;
		margin-right: 2vw;
	}

	.search_box .search input {
		flex: 1;
		font-size: 3.5vw;
		color: #333;
	}

	.search_box .search .menu {
		font-size: 4vw;
		height: 9vw;
		width: 16vw;
		color: #fff;
		background-color: #FE811E;
		border-radius: 2vw;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 1.5vw;
	}

	.rule_box {
		width: 100%;
		height: 10vw;
		background-color: #FEF6EB;
		display: flex;
		align-items: center;
		padding: 0 4%;
	}

	.rule_box .icon {
		font-size: 5vw;
		color: #FF6B23;
		margin-right: 2vw;
	}

	.rule_box .value {
		flex: 1;
		font-size: 3.5vw;
		color: #FF6B23;
		margin-right: 2vw;
	}

	.rule_box .add {
		font-size: 3.5vw;
		color: #FF6B23;
		margin-right: 1vw;
	}

	.rule_box .arrow {
		font-size: 4vw;
		color: #FF6B23;
	}

	.group_list {
		width: 100%;
		padding: 4%;
		background-color: #fff;
		display: flex;
		align-items: center;
	}

	.group_list .group_img {
		width: 15vw;
		margin-right: 3vw;
	}

	.group_list .group_img image {
		width: 100%;
	}

	.group_list .group_text {
		flex: 1;
	}

	.group_list .group_text .title {
		font-size: 4vw;
		color: #333;
		font-weight: bold;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
	}

	.group_list .group_text .text {
		font-size: 3.5vw;
		color: #666666;
		margin-top: 3vw;
	}

	.group_list .group_menu {
		font-size: 3.8vw;
		color: #fff;
		width: 17vw;
		height: 10vw;
		border-radius: 10vw;
		background: linear-gradient(to right, #FE9229, #FF4F27);
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.pupu_box {
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.7);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 9999;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}
	
	.pupu_box .pupu_show {
		width: 100%;
		background-color: #fff;
		border-radius: 4vw 4vw 0 0;
		padding: 5vw 4vw;
		position: relative;
	}
	
	.pupu_box .pupu_show .pupu_title{
		font-size: 4.5vw;
		color: #333;
		text-align: center;
		font-weight: bold;
		padding-bottom: 5vw;
	}
	
	.pupu_box .pupu_show .close{
		font-size: 4vw;
		color: #333;
		text-align: center;
		position: absolute;
		right: 5vw;
		top: 5vw;
	}
	
	.pupu_box .pupu_show .pupu_value{
		max-height: 70vh;
		width: 100%;
		overflow-x: hidden;
		overflow-y: scroll;
		
	}
	
	.pupu_box .pupu_show .pupu_value .ewm{
		width: 30vw;
		height: 30vw;
		margin: 0 auto;
	}
	
	.pupu_box .pupu_show .pupu_value .ewm image{
		width: 100%;
		height: 100%;
	}
	
	.pupu_menu{
		width: 100%;
		height: 13vw;
		border-radius: 13vw;
		line-height: 13vw;
		text-align: center;
		background-color: #FC5D20;
		color: #fff;
		font-size: 4vw;
		margin: 0 auto;
		margin-top: 8vw;
		font-weight: bold;
	}
</style>